package com.ruoyi.upload.controller;

import com.ruoyi.upload.service.FileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RestController
@CrossOrigin //处理跨域
public class FileController {

    @Resource
    private FileService fileService;
    @PostMapping("FileController/testFileImage/upload")
    public String testFileImage(@RequestParam("file") MultipartFile multipartFile, HttpServletRequest request) {
        String originalFilename = multipartFile.getOriginalFilename();
         // todo 写请求头
        byte[] bytes;
        try {
            bytes = multipartFile.getBytes();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //需要文件字节数组 和文件名
        String upload = fileService.upload(bytes, originalFilename,request);
        System.out.println(upload);
        return upload;
    }
}
